//
//  HTKSampleCollectionViewCell.m
//  HTKDragAndDropCollectionView
//
//  Created by Henry T Kirk on 11/9/14.
//  Copyright (c) 2014 Henry T. Kirk (http://www.henrytkirk.info)
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
#import "UIView+EV.h"
#import "UIColor+EV.h"
#import "UIImageView+WebCache.h"
#import "HTKSampleCollectionViewCell.h"

@interface HTKSampleCollectionViewCell (){
    
}
@end

@implementation HTKSampleCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}

- (instancetype) initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
        gesture.direction = UISwipeGestureRecognizerDirectionRight|UISwipeGestureRecognizerDirectionLeft;
        [self addGestureRecognizer:gesture];
    }
    return self;
}

- (instancetype) init {
    self = [super init];
    if (self) {
        UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
        gesture.direction = UISwipeGestureRecognizerDirectionRight;
        [self addGestureRecognizer:gesture];
    }
    return self;
}

- (void) setModel:(LSYReadModel *)model {
    _model = model;
    _numberLabel.text = _model.title;
    [_coverView sd_setImageWithURL:[NSURL URLWithString:_model.netBook.bookIcon] placeholderImage:[UIImage imageNamed:@"ic_book_cover"]];
    _percentLabel.text = _model.percentStrig;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _coverView.layer.shadowColor = [UIColor colorWithRed:110/255.0 green:109/255.0 blue:124/255.0 alpha:1].CGColor;//阴影颜色
    _coverView.layer.shadowOffset = CGSizeMake(0, 3);//偏移距离
    _coverView.layer.shadowOpacity = 0.8;//不透明度
}

- (void) setEditing:(BOOL)editing {
    _editing = editing;
    _delBtn.hidden = !_editing;
}

- (void)longPress:(id)sender {
    if(self.draggingDelegate && [self.draggingDelegate respondsToSelector:@selector(longPressCell:)]) {
        [self.draggingDelegate longPressCell:self];
    }
}

// del all
- (IBAction)del:(UIButton *)btn {
    if (self.draggingDelegate && [self.draggingDelegate respondsToSelector:@selector(deleteCell:obj:)]) {
        [self.draggingDelegate deleteCell:self obj:btn];
    }
}

@end
